package com.swlz.service.impl;

import java.sql.SQLException;

import com.swlz.dao.WebCommentDAO;
import com.swlz.entity.WebComment;
import com.swlz.exception.CodeException;
import com.swlz.service.WebCommentService;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 网站评论
 * ClassName : com.swlz.service.impl.WebCommentServiceImpl
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-06-23 18:03:35
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class WebCommentServiceImpl implements WebCommentService {
	
	private WebCommentDAO webCommentDAO = new WebCommentDAO();

	@Override
	public int add(WebComment webComment) throws CodeException {
		try {
			return webCommentDAO.insertSelective(webComment);
		} catch (SQLException e) {
			throw new CodeException(500, "添加网站评论错误",e);
		}
	}

	@Override
	public int update(WebComment webComment) throws CodeException {
		try {
			return webCommentDAO.updateSelective(webComment);
		} catch (SQLException e) {
			throw new CodeException(501, "修改网站评论错误",e);
		}
	}

	@Override
	public int delete(Long commentId) throws CodeException {
		try {
			return webCommentDAO.deleteById(commentId);
		} catch (SQLException e) {
			throw new CodeException(502, "删除网站评论错误",e);
		}
	}

	@Override
	public WebComment get(Long commentId) throws CodeException {
		try {
			return webCommentDAO.selectById(commentId);
		} catch (SQLException e) {
			throw new CodeException(503, "获取网站评论失败",e);
		}
	}

	@Override
	public PageVO<WebComment> page(WebComment webComment, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = webCommentDAO.countByModel(webComment);
			PageVO<WebComment> page = new PageVO<>(total, current, rowMax);
			return page.setList(webCommentDAO.selectByModel(webComment, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			throw new CodeException(504, "获取网站评论分页数据失败",e);
		}
	}


}
